#1.1
#我的博客：https://zhfhz.gitee.io/
import requests
import json
operation = input("1.请确保公共用户赵铁柱提交过试卷\n2.详细请看我博客https://zhfhz.gitee.io\n3.请按回车键开始\n")
##登录模块
page_url = 'https://m.umu.cn/passport/ajax/account/login'
payload = {"username": 'zmsxre34026@chacuo.net', "passwd": "zmsxre34026"}  # 值以字典的形式传入
response = requests.post(page_url, data=payload)
response.encoding = 'utf-8'
html = response.text
user_cookie = response.cookies  # 获取cookies
user_json = json.loads(html)  # 用户信息
print("正在登录公共用户赵铁柱")
print("用户ID：" + user_json['data']['user_info']['umu_id'])
print("用户名称：" + user_json['data']['user_info']['user_name'])
if user_json['data']['user_info']['umu_id'] == "赵铁柱":
    print("用户登录成功！")
for item in user_cookie:
    item = str(item)
    if item.find("JSESSID") != -1:
        # print(item)
        JSESSID = item[item.find("JSESSID") + 8:item.find("for .umu.cn") - 1]
    if item.find("umuU") != -1:
        # print(item)
        umuU = item[item.find("umuU") + 5:item.find("for .umu.cn") - 1]
##解析模块
sessionId = input("输入试卷ID后按回车键确认\n")  # 试卷ID 26802132
questionId = input("输入问题ID后按回车键确认\n")  # 问题ID 4837358
while questionId != "":
    page_url = "https://m.umu.cn/napi/v1/quiz/question-right-answer?t=1586269428055&_type=1&element_id=" + sessionId + "&question_ids=" + questionId
    cookies = {"umuU": umuU, "JSESSID": JSESSID,
               "_lang": "zh-cn",
               "Hm_lvt_0dda0edb8e4fbece1e49e12fc49614dc": "1586319220",
               "Hm_lpvt_0dda0edb8e4fbece1e49e12fc49614dc": "1586319427"}
    response = requests.get(page_url, cookies=cookies)
    response.encoding = 'utf-8'
    html = response.text
    data_json = json.loads(html)
    msg_len = len(data_json['data'][questionId])
    print("共：" + str(msg_len) + "个答案")
    for msg_id in range(msg_len): #循环所有答案
        print("答案ID是：" + str(data_json['data'][questionId][msg_id]['right_answer_id']))
    questionId = input("输入问题ID后按回车键确认\n")
